
<@override name="title">
添加首页推荐
</@override>

<@override name="content">
<div class="content">
    <div class="container-fluid">
        <div class="panel panel-default block-body">
            <div class="panel-heading">首页推荐添加（修改）</div>
            <form id="recommendForm" class="panel-body" action="${base}/mergeRecommend" method="POST">
                <input type="hidden" name="id" value="${(entity.id)!}" />
                <div class="form-group clearfix">
                    <label class="control-label">推荐图片</label>
                    <div class="col-md-8">
                        <#if (entity.picture)?? && entity.picture != '0'>
                        <img id="imagePreview" style="width: 250px;height: 90px;background-image: url('/file/attachment/${entity.picture}/m');background-size: contain;">
                        <#else>
                        <img id="imagePreview" style="display: none;width: 250px;height: 90px;background-size: contain;">
                        </#if>
                        <input type="file" id="file" style="margin-top:3px;">
                        <span>尺寸：1200 x 440</span>
                        <input type="hidden" name="recommdPicture" id="recommdPicture">
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="control-label">课程名称</label>
                    <div class="col-md-8">
                        <input id="name" type="text" class="form-control" name="name" value="${(entity.name)!}" placeholder="请输入名称">
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="control-label" >课程链接</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" name="url" value="${(entity.url)!}" id="url" placeholder="请输入链接">
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="control-label" >推荐权重</label>
                    <div class="col-sm-8">
                        <input type="number" class="form-control" name="weight" value="${(entity.weight)!}" id="weight" placeholder="请输入权重">
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="control-label" >是否禁用</label>
                    <div class="col-sm-8">
                        <select name="enable" id="enable" class="form-control" >
                            <option value="1" <#if (entity.enable)?? && entity.enable == 1>selected</#if> >可用</option>
                            <option value="0" <#if (entity.enable)?? && entity.enable == 0>selected</#if> >禁用</option>
                        </select>
                    </div>
                </div>

                <div id="_alertInfo" class="alert-info" style="display: none;"></div>

                <div class="modal-footer">
                    <button type="button" onclick="doSubmit()" class="btn btn-primary">保存</button>
                    <button type="button" onclick="window.history.go(-1)" class="btn btn-default">取消</button>
                </div>

            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    function doSubmit() {
        let name = $('#name').val();
        if(_os.isEmpty(name)){
            // Modal.alert('名字不能为空');
            _os.alertMsg('名字不能为空');
            return;
        }
        $('#recommendForm').submit();
    }

    //选择图片的时候
    $('#file').change(function(evt){
        let f = $('#file').val();//获取文件的名字
        if(_os.photoValid(f)){
            let file = $('#file').get(0).files[0];//获取文件本身
            _os.processImageFile(file,function(r){
                $('#imagePreview').css('background-image','url('+r.image+')');
                $('#imagePreview').show();
                $('#recommdPicture').val(r.data);
            })
        }else{
            _os.alertMsg('图片格式不正确');
        }
    })

</script>

</@override>

<@extends name="_manage_base.html" />